#!/usr/bin/env python
# -*- encoding: utf-8 -*-


class Scope(object):
    allow_api = []
    allow_module = []
    forbidden = []

    def __add__(self, other):
        self.allow_api = self.allow_api + other.allow_api
        self.allow_api = list(set(self.allow_api))

        self.allow_module = self.allow_module + other.allow_module
        self.allow_module = list(set(self.allow_module))

        self.forbidden = self.forbidden + other.forbidden
        self.forbidden = list(set(self.forbidden))
        return self


class AdminScope(Scope):
    allow_api = [
        'super_get_user',
    ]

    def __init__(self):
        pass


class UserScope(Scope):

    def __init__(self):
        self + AdminScope


def is_in_scope(scope, endpoint):
    # global() 函数获取当前模块(文件)下所有信息
    # 以属性字符串形式存储类信息
    scope = globals()[scope]()
    splits = endpoint.split('+')
    point_name = splits[0]

    if endpoint in scope.forbidden:
        return False
    elif endpoint in scope.allow_api:
        return True
    elif point_name in scope.allow_module:
        return True
    else:
        return False
